<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=kviF2GeQXkhb0NXyhdRbODFAe5GKb1x3"></script>
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" href="../css/style.css">

    <style type="text/css">
        /*body, html, #allmap {*/
        /*width: 100%;*/
        /*height: 100%;*/
        /*overflow: hidden;*/
        /*margin: 0;*/
        /*font-family: "微软雅黑";*/
        /*}*/

        .map {
            width: 100%;
            height: 430px;
        }

        .map_info {
            width: 100%;
            height: 600px;
        }

        #l-map {
            height: 100%;
            width: 100%;
        }


    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页
            <small>公司分布图</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <!--<template>-->
            <el-tabs v-model="activeName" type="card" >
                <el-tab-pane label="分布图" name="first">
                    <div class="map">
                        <div id="l-map"></div>
                    </div>
                </el-tab-pane>
                <el-tab-pane label="详细信息" name="second">
                    <div class="map_info">
                        <div class="filter-container">
                            <el-input placeholder="公司地址" v-model="pagination.queryString"
                                      style="width: 200px;"
                                      class="filter-item"></el-input>
                            <el-button @click="findPage2()" class="dalfBut">查询</el-button>
                            <el-button type="primary" class="butT" @click="handleClick">新建
                            </el-button>
                        </div>
                        <el-table size="small" current-row-key="id" :data="dataList" stripe
                                  highlight-current-row>
                            <el-table-column type="index" align="center" label="序号"></el-table-column>
                            <el-table-column prop="address" label="公司地址" align="center"></el-table-column>
                            <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                            <el-table-column prop="latitude" label="所在维度" align="center"></el-table-column>
                            <el-table-column label="操作" align="center">
                                <template slot-scope="scope">
                                    <el-button type="danger" size="mini" @click="handleDelete(scope.row)">
                                        删除
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="pagination-container">
                            <el-pagination
                                    class="pagiantion"
                                    @current-change="handleCurrentChange"
                                    :current-page="pagination.currentPage"
                                    :page-size="pagination.pageSize"
                                    layout="total, prev, pager, next, jumper"
                                    :total="pagination.total">
                            </el-pagination>
                        </div>
                        <el-dialog title="新增地址" :visible.sync="dialogFormVisible">
                            <div style="height: 450px;width: 100%;margin-top: -20px">
                                <iframe id="iframe1" src="baidu_address.html"
                                        style="width: 102%;height: 100%;margin: 0px;padding: 0px;border: 0px"></iframe>
                            </div>
                        </el-dialog>
                    </div>
                </el-tab-pane>
            </el-tabs>
            <!--</template>-->
        </div>
    </div>
</div>
</body>
</html>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script type="text/javascript">

    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            input: '',
            dataList: [],//当前页要展示的分页列表数据
            map: null,
            map2: null,
            ac: null,
            dialogFormVisible: false,
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
            // this.findAllMap();

        },
        //钩子函数,已完成模板已经渲染或el对应html渲染后
        mounted() {
            //分布图:地图初始化
            this.map = new BMap.Map("l-map");
            this.map.centerAndZoom(new BMap.Point(114.3170090, 30.5313890), 13);
            this.map.addControl(new BMap.MapTypeControl({
                mapTypes:[
                    BMAP_NORMAL_MAP,
                    BMAP_HYBRID_MAP
                ]}));
            this.map.enableScrollWheelZoom(true);
            this.findAllMap();
        }, methods: {
            //查询所有地图信息
            findAllMap(){
                this.map.clearOverlays();
                axios.post("/mapinfo/findAll.do").then((res)=>{
                    var dataList=res.data.data;
                    console.log(dataList);
                    for (var i = 0; i < dataList.length; i++) {
                        var marker = new BMap.Marker(new BMap.Point(dataList[i].longitude, dataList[i].latitude))
                        this.map.addOverlay(marker);
                        marker.setLabel(new BMap.Label(dataList[i].address, {offset: new BMap.Size(20, -10)}));
                    }
                })
            },
            //分页查询
            findPage() {
                this.dialogFormVisible = false;
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }
                axios.post("/mapinfo/findPage.do", param).then((res) => {
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                })
            },

            findPage2() {
                this.pagination.currentPage = 1;
                this.findPage();
            },

            handleClick(tab, event) {
                this.dialogFormVisible = true;
                document.getElementById("iframe1").contentWindow.location.reload(true);
            },

            //切换页面
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            //删除
            handleDelete(row) {
                this.$confirm("你确定要删除当前数据吗?","提示",{
                    type: "warning"
                }).then(()=>{
                    axios.get("/mapinfo/delete.do?id="+row.id).then((res)=>{
                        if (res.data.flag){
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            this.findPage();
                            this.findAllMap();
                        }else {
                            this.$message.error(res.data.message)
                        }
                    })
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    })
                })
            }
        }
    })


</script>
